<template>
    <van-form @submit="onSubmit" style="padding-top: 20px;">
        <van-cell-group inset>
            <van-field v-model.trim="content" name="content" label="反馈内容" placeholder="请输入反馈内容" required type="textarea"
                :rows="8" :rules="[{ required: true, message: '请填写反馈内容' }]" />
        </van-cell-group>
        <div style="margin: 16px;">
            <van-button round block type="primary" native-type="submit">
                提交
            </van-button>
        </div>
    </van-form>
</template>

<script setup>
import { onMounted, reactive, ref } from 'vue';
import Api from '@/api/homePage'
import { Toast } from 'vant';
import { useRouter } from 'vue-router';
const router = useRouter();

const content = ref('');
const onSubmit = (values) => {
    if (!content.value) {
        return false
    }
    const toast = Toast.loading({
        message: '加载中...',
        forbidClick: true,
    });
    Api.addFeedback({
        content: content.value,
        userId: localStorage.getItem('userId')
    }).then(res => {
        Toast.success('提交成功');
        content.value = ''
        setTimeout(() => {
            toast.clear()
            router.go(-1)
        }, 1000)
    }).catch(() => {
        toast.clear()
    })
};
</script>

<style lang="scss" scoped></style>